#include "initPoint.h"
#include "ui_initPoint.h"

#include <QDebug>
#include <QPainter>

initPoint::initPoint(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::initPoint)
{
    ui->setupUi(this);

    pointFile.setFileName(pointFilePath);
    ui->radioBtn_crossing->setChecked(true);

    connect(ui->radioBtn_crossing, &QRadioButton::clicked, [=](){
        type = 0;
    });
    connect(ui->radioBtn_building, &QRadioButton::clicked, [=](){
        type = 1;
    });
    connect(ui->btn_save, &QPushButton::clicked, [=](){
        SavePoint(ui->line_pointName->text());
        this->close();
        Init();
    });
}

initPoint::~initPoint()
{
    delete ui;
}

void initPoint::GetPoint(int x, int y, int campus)
{
    this->x = x;
    this->y = y;
    this->campus = campus;
    ui->lbl_information->setText("当前点：x = " + QString::number(x) +
                                 "；y = " + QString::number(y));
}

void initPoint::SavePoint(QString name)
{
    if( ! pointFile.open(QIODevice::Append))
        qDebug() << "打开点文件错误";
    QTextStream stream(&pointFile);
    QString point = name + " " +
            QString::number(x) + " " +
            QString::number(y) + " " +
            QString::number(campus) + " " +
            QString::number(type);
    stream << point << "\r\n";
    pointFile.close();
}

void initPoint::Init(void)
{
    ui->line_pointName->setText(NULL);
    ui->radioBtn_crossing->setChecked(true);
    type = 0;
}
